package com.bustle.web.mbean.request;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.bustle.facade.proxy.AuthenticationDtoManagerProxy;
import com.bustle.order.OrderManager;
import com.bustle.order.data.Order;
import com.bustle.user.dto.user.UserDto;
import com.bustle.web.mbean.session.UserMBean;

@ManagedBean(name = "orderMB")
@RequestScoped
public class OrderMBean
{

  private List<Order> orders;
  private UserDto user;
  @ManagedProperty(value = "#{param.orderId}")
  private int orderId;
  private Order order;
  @ManagedProperty(value = "#{userMBean}")
  private UserMBean userMBean;
  @EJB
  private AuthenticationDtoManagerProxy authManager;
  @EJB
  private OrderManager orderManager;

  @PostConstruct
  public void postConstruct()
  {
    if (userMBean.getId() != null)
    {
      user = authManager.getUser(userMBean.getId());
      orders = orderManager.getOrdersByUser(user.getId());
    }
  }

  public String getDetails()
  {
    System.out.println("Commande n° " + orderId);
    order = orderManager.getById(orderId);
    return "consulterCommande.jsf";
  }


  public List<Order> getOrders()
  {
    return orders;
  }
  public void setOrders(List<Order> orders)
  {
    this.orders = orders;
  }

  public UserDto getUser()
  {
    return user;
  }
  public void setUser(UserDto user)
  {
    this.user = user;
  }
  public UserMBean getUserMBean()
  {
    return userMBean;
  }
  public void setUserMBean(UserMBean userMBean)
  {
    this.userMBean = userMBean;
  }

  public int getOrderId()
  {
    return orderId;
  }

  public void setOrderId(int orderId)
  {
    this.orderId = orderId;
  }

  public Order getOrder()
  {
    return order;
  }

  public void setOrder(Order order)
  {
    this.order = order;
  }

}
